package com.dld.coupon.db;

import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;

import com.dld.android.util.LogUtils;
import com.dld.android.util.ReflectionFactory;
import com.dld.protocol.json.BankCouponDetail;
import com.dld.protocol.json.CouponDetail;
import com.dld.protocol.json.Detail;
import com.dld.protocol.json.DetailRef;
import com.dld.protocol.json.GroupDetail;
import com.dld.protocol.json.Ticket;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONObject;

public class FriendFav {
    public static void delete(SQLiteDatabase paramSQLiteDatabase,
            int paramInt1, int paramInt2) {
        String[] arrayOfString = new String[2];
        arrayOfString[0] = String.valueOf(paramInt1);
        arrayOfString[1] = String.valueOf(paramInt2);
        paramSQLiteDatabase.delete("fav", "id = ? and user_id = ?",
                arrayOfString);
    }

    public static String getAllStores(SQLiteDatabase paramSQLiteDatabase,
            String paramString) {
        String str = null;
        Object localObject = new StringBuffer();
        Cursor localCursor = paramSQLiteDatabase
                .rawQuery("SELECT * FROM friend_fav " + paramString
                        + " ORDER BY id DESC", null);
        if (localCursor.moveToFirst())
            ;
        try {
            int i = localCursor.getInt(1);
            JSONObject localJSONObject = new JSONObject(
                    localCursor.getString(2));
            switch (i) {
            default:
            case 0:
                while (!localCursor.moveToNext()) {
                    localCursor.close();
                    localObject = ((StringBuffer) localObject).toString();
                    if (((String) localObject).length() != 0)
                        // break label197;
                        return str;
                    ((StringBuffer) localObject).append(
                            ((CouponDetail) ReflectionFactory.create(
                                    localJSONObject, CouponDetail.class)).id)
                            .append(",");
                }
            case 1:
            }
        } catch (Exception localException) {
            // while (true)
            {
                JSONObject localJSONObject = null;
                LogUtils.e("test", "", localException);
                // continue;
                try {
                    ((StringBuffer) localObject).append(
                            ((CouponDetail) ReflectionFactory.create(
                                    localJSONObject, CouponDetail.class)).id)
                            .append(",");
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                // continue;
                label197: str = ((String) localObject).substring(0, -1
                        + ((String) localObject).length());
            }
        }
        return str;
    }

    // ERROR //
    public static String getCanByGroupString(
            SQLiteDatabase paramSQLiteDatabase, String paramString) {
       
        return null;
    }

    public static long getCount(SQLiteDatabase paramSQLiteDatabase) {
        return DatabaseUtils.queryNumEntries(paramSQLiteDatabase, "friend_fav");
    }

    // ERROR //
    public static String getCouponIdString(SQLiteDatabase paramSQLiteDatabase,
            String paramString) {
		return null;
       
    }

    // ERROR //
    public static int getFavCountByType(SQLiteDatabase paramSQLiteDatabase,
            String paramString) {
      
        return 0;
    }

    // ERROR //
    public static String getIdString(SQLiteDatabase paramSQLiteDatabase,
            String paramString) {
       
        return null;
    }

    // ERROR //
    public static String getStroeIdString(SQLiteDatabase paramSQLiteDatabase,
            String paramString) {
      
        return null;
    }

    public static void init(SQLiteDatabase paramSQLiteDatabase) {
        paramSQLiteDatabase
                .execSQL("CREATE TABLE IF NOT EXISTS friend_fav(id INTEGER PRIMARY KEY, type INTEGER, content TEXT, user_id INTEGER)");
    }

    public static List<DetailRef> list(SQLiteDatabase paramSQLiteDatabase,
            String paramString) {
        ArrayList localArrayList = new ArrayList();
        Cursor localCursor = paramSQLiteDatabase
                .rawQuery("SELECT * FROM friend_fav " + paramString
                        + " ORDER BY id DESC", null);
        if (localCursor.moveToFirst())
            ;
        try {
            int j = localCursor.getInt(0);
            int i = localCursor.getInt(1);
            switch (i) {
            case 3:
            case 4:
                // while (true)
            {
                Object localObject = new DetailRef();
                Detail localDetail = (Detail) ReflectionFactory.create(
                        new JSONObject(localCursor.getString(2)),
                        DetailRef.class);
                ((DetailRef) localObject).type = i;
                ((DetailRef) localObject).detail = localDetail;
                localDetail.setDBId(j);
                localArrayList.add(localObject);
                if (localCursor.moveToNext()) {
                    // break;
                    localCursor.close();
                    return localArrayList;
                }
                // localObject = BankCouponDetail.class;
                // continue;
                localObject = Ticket.class;
            }
            default:
            case 2:
            }
        } catch (Exception localException) {
            // while (true)
            {
                LogUtils.e("test", "", localException);
                // continue;
                Object localObject = CouponDetail.class;
                // continue;
                localObject = GroupDetail.class;
            }
        }
        return localArrayList;
    }

    public static Map<String, DetailRef> listAsMap(
            SQLiteDatabase paramSQLiteDatabase, String paramString) {
        HashMap localHashMap = new HashMap();
        Cursor localCursor = paramSQLiteDatabase
                .rawQuery("SELECT * FROM friend_fav " + paramString
                        + " ORDER BY id DESC", null);
        if (localCursor.moveToFirst())
            ;
        try {
            do {
                int i = localCursor.getInt(1);
                int j = localCursor.getInt(0);
                switch (i) {
                case 3:
                    Object localObject = new DetailRef();
                    Detail localDetail = (Detail) ReflectionFactory.create(
                            new JSONObject(localCursor.getString(2)),
                            DetailRef.class);
                    ((DetailRef) localObject).type = i;
                    ((DetailRef) localObject).detail = localDetail;
                    localDetail.setDBId(j);
                    localHashMap.put(localDetail.getId(), localObject);
                case 4:
                default:
                case 2:
                }
            } while (localCursor.moveToNext());
        } catch (Exception localException1) {
            // while (true)
            {
                try {
                    localCursor.close();
                    // return localHashMap;
                    // localObject = BankCouponDetail.class;
                    // continue;
                    // localObject = Ticket.class;
                    // continue;
                    localException1 = localException1;
                    LogUtils.e("test", "", localException1);
                } catch (Exception localException2) {
                    // continue;
                    // localObject = CouponDetail.class;
                }
                // continue;
                Object localObject = GroupDetail.class;
            }
        }
        return localHashMap;
    }

    public static void save(SQLiteDatabase paramSQLiteDatabase, int paramInt1,
            Object paramObject, int paramInt2) {
        String str = ReflectionFactory.toJSON(paramObject).toString();
        Object[] arrayOfObject = new Object[3];
        arrayOfObject[0] = Integer.valueOf(paramInt1);
        arrayOfObject[1] = str;
        arrayOfObject[2] = Integer.valueOf(paramInt2);
        paramSQLiteDatabase
                .execSQL(
                        "INSERT INTO friend_fav(type, content, user_id) VALUES(?, ?, ?)",
                        arrayOfObject);
    }
}
